#pragma once

#include "CollaborationUse.h"

#include "Collaboration.h"
#include "Dependency.h"

namespace uml {

CollaborationUse::CollaborationUse(const QString& umlType)
    : NamedElement(umlType) {}

void CollaborationUse::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    NamedElement::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(roleBindings_, "roleBindings", json, errorList);
    type_ = JsonSerializable::create<Collaboration>(json.value("type"), errorList);

}

void CollaborationUse::toJson(QJsonObject& json) {
    NamedElement::toJson(json);
    JsonSerializable::toJsonArray(roleBindings_, "roleBindings", json);
    if (type_) {
        QJsonObject type_json;
        type_->toJson(type_json);
        json.insert("type", type_json);
    }
}

/// <summary>
/// roleBindings getter
/// A mapping between features of the Collaboration and features of the owning
/// Classifier. This mapping indicates which ConnectableElement of the Classifier
/// plays which role(s) in the Collaboration. A ConnectableElement may be bound to
/// multiple roles in the same CollaborationUse (that is, it may play multiple
/// roles).
/// </summary>
vector<shared_ptr<Dependency>>& CollaborationUse::roleBindings() {
    return roleBindings_;
}

/// <summary>
/// type getter
/// The Collaboration which is used in this CollaborationUse. The Collaboration
/// defines the cooperation between its roles which are mapped to
/// ConnectableElements relating to the Classifier owning the CollaborationUse.
/// </summary>
shared_ptr<Collaboration> CollaborationUse::type() const {
    return type_;
}

/// <summary>
/// type setter
/// The Collaboration which is used in this CollaborationUse. The Collaboration
/// defines the cooperation between its roles which are mapped to
/// ConnectableElements relating to the Classifier owning the CollaborationUse.
/// </summary>
void CollaborationUse::setType(shared_ptr<Collaboration> value) {
    type_ = value;
}

} // namespace uml
